layui.use(['element', 'layer','flow','rate','form','util'], function(){
    var element = layui.element,
    layer = layui.layer,
    flow = layui.flow,
    rate = layui.rate,
    form = layui.form,
    util = layui.util,
    $ = layui.$;
    
    //每一页的数据条数
	var limit = 8;
	var laef = 0;
	
	loadFlow();

	//layui流加载
	function loadFlow(state){
		$("#flowDiv").replaceWith('<div id="flowDiv"><div class="related" style="margin-top: -0.2%;" id="ordersDiv"><div class="layui-collapse" lay-filter="test"></div></div></div>');
		flow.load({
			elem: '#ordersDiv'	//流加载容器
			,isAuto: false
			,done: function(page,next){	//执行下一页的回调
				//模拟数据插入
				setTimeout(function(){
					var lis = [];
					//加载订单
					loadOrders(page,state);
					next(lis.join(''),page < laef);
				},500);
			}
		});
	}
	
	//动态选项卡的监听(城市)
	element.on('tab(ordersTypeTab)', function(elem){
		$(".layui-collapse").html('');
		if(elem.index>0){
			loadFlow(elem.index);
		}else{
			loadFlow();
		}
	});
	
	//获取生成时间后30分钟的时间
	function getEndDate(endDate,oid){
		$.ajax({
			type:"post",
			url:"orders/getEndDate",
			async:false,
			data:{endDate:endDate},
			success:function(data){
				getdate(formatDateTime(data),oid);
			},error:function(){
				swal("服务器异常!","","warning",{buttons: {}});
			}
		});
	}

	//获取计时器(倒计时)
	function getdate(endOrdersDate,oid){
		var time = endOrdersDate.split(",");
		//调用显示倒计时的方法
		setCountdown(time[0],time[1]-1,time[2],time[3],time[4],time[5],oid);
	}
	//倒计时
	function setCountdown(y, M, d, H, m, s,oid){
	    var endTime = new Date(y, M||0, d||1, H||0, m||0, s||0) //结束日期
	    ,serverTime = new Date(); //假设为当前服务器时间，这里采用的是本地时间，实际使用一般是取服务端的
	    
	    util.countdown(endTime, serverTime, function(date, serverTime, timer){
	      var str = date[0] + '天' + date[1] + '时' +  date[2] + '分' + date[3] + '秒';
	      $('#date'+oid).html("还剩："+str);
	      if($('#date'+oid).text()=="还剩：0天0时0分0秒"){
			  var datebtn = $(this).parent().siblings().eq(7).text();
			  console.log(datebtn);
			  $('#date'+oid).html('<span style="color:gray;margin-left: 42px;">已失效</span>');
			  $("#ordersPay"+oid).html('<button class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon">&#xe702;</i>已失效</button>');
	    	  $('#payBtn'+oid).replaceWith('<button class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon">&#xe702;</i>已失效</button>');
	      }
	    });
	    return false;
	};
	
	//加载房屋数据
	function loadOrders(page,state){
		var jsonOrders = {};
		jsonOrders['user.uid'] = $("#uid").val();
		jsonOrders['state'] = state;
		jsonOrders['page'] = page;
		jsonOrders['limit'] = limit;
		$.ajax({
			url: 'orders/listByPramas',
			type: 'post',
			data:jsonOrders,
			async: false,
			success:function(res){
				if(res.code==0){
					var htmlContent = '';
					$.each(res.data,function(i,item){
						htmlContent += '<div class="layui-colla-item">';
	      				htmlContent += '<ul class="layui-nav layui-colla-title" id="layui-nav" style="height: 70px;background-color: #FFF0F5; ">';
	      				htmlContent += '<li class="layui-nav-item" style="display: none;">'+item.oname+'</li>';
	      				htmlContent += '<li class="layui-nav-item" style="display: none;">'+item.oprice+'</li>';
	      				htmlContent += '<li class="layui-nav-item" style="margin-left: 0%;width: 80px;">'+item.oname+'</li>';
	      				htmlContent += '<li class="layui-nav-item" style="margin-left: 6.8%;width: 180px;"><span style="color:#FF5722 ">'+item.makeOrderDate+'</span></li>';
	      				htmlContent += '<li class="layui-nav-item" style="margin-left: -2.4%;width: 80px;"><span style="color: #FF5722">$'+item.oprice+'</span></li>';
	      				htmlContent += '<li class="layui-nav-item" style="margin-left: 6.3%;width: 220px;"><span style="color: #FF5722">'+item.address.loc+'</span></li>';
	      				if(item.state==1){
		      			   getEndDate(item.makeOrderDate,item.oid);
	      				   htmlContent += '<li class="layui-nav-item" style="margin-left: 6%;width: 150px;"><span id="date'+item.oid+'" style="color: red;"></span></li>';
	      				   htmlContent += '<li class="layui-nav-item" style="margin-left: 6.5%;width: 80px;"><span id="ordersPay'+item.oid+'"><button class="layui-btn layui-btn-danger layui-btn-xs" id="ordersPay"><i class="layui-icon">&#xe65e;</i>去支付</button></span></li>';
	      				}else if(item.state==2){
	      					htmlContent += '<li class="layui-nav-item" style="margin-left: 10%;width: 80px;"><span style="color:blue;">已支付</span></li>';
	       				   htmlContent += '<li class="layui-nav-item" style="margin-left: 8.8%;width: 80px;"><button class="layui-btn layui-btn-normal layui-btn-xs" id="ordersFinish" value="'+item.gids+' '+item.gcids+' '+item.gsids+' '+item.cnums+'"><i class="layui-icon">&#xe623;</i>去收货</button></li>';
	      				}else if(item.state==3){
	      					htmlContent += '<li class="layui-nav-item" style="margin-left: 10%;width: 80px;"><span style="color:green;">已收货</span></li>';
	        				htmlContent += '<li class="layui-nav-item" style="margin-left: 8.8%;width: 80px;"><button class="layui-btn layui-btn-xs" id="ordersComm"><i class="layui-icon">&#xe6b2;</i>去评价</button></li>';
	       				}else if(item.state==4){
	      					htmlContent += '<li class="layui-nav-item" style="margin-left: 10%;width: 80px;"><span style="color:gray;">已评价</span></li>';
	        				htmlContent += '<li class="layui-nav-item" style="margin-left: 8.8%;width: 80px;"><button class="layui-btn layui-btn-primary layui-btn-xs" id="ordersLook"><i class="layui-icon">&#xe705;</i>去查看</button></li>';
	       				}else{
	      					htmlContent += '<li class="layui-nav-item" style="margin-left: 10%;width: 80px;"><span style="color:gray;">已失效</span></li>';
	        				htmlContent += '<li class="layui-nav-item" style="margin-left: 8.8%;width: 80px;"><button class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon">&#xe702;</i>已失效</button></li>';
	       				}
	      				htmlContent += '</ul>';
	      				htmlContent += '<div class="layui-colla-content">';
      					htmlContent += '<table class="layui-table" lay-even="" lay-skin="nob">';
      					htmlContent += '<thead><tr><th>商品</th><th>名称</th><th>折后价</th><th>类型</th><th>类型简介</th><th>颜色</th><th>尺寸</th><th>数量</th><th>总价</th><th>操作</th></tr></thead>';
	      				$.each(item.ordersList,function(i,ordersBean){
	      					if(item.state==1){
	      						htmlContent += '<tbody><tr><td><a href="good/goodDetails?gid='+ordersBean.gid+'"><img style="width: 50px;margin-top: 10px;" src="/zzbinGood/'+ordersBean.gpricpath+'"></a>&nbsp;&nbsp;</td><td width="170px">'+ordersBean.gname+'</td><td>$'+(ordersBean.price*ordersBean.discount).toFixed(2)+'</td><td>'+ordersBean.tname+'</td><td>'+ordersBean.tdesc+'</td><td>'+ordersBean.gcname+'</td><td>'+ordersBean.gsname+'</td><td>'+ordersBean.cnum+'</td><td>$'+ordersBean.cprice+'</td><td><button id="payBtn'+item.oid+'" class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon">&#xe65e;</i>待支付</button></td></tr></tbody>';
	      					}else if(item.state==2){
	      						htmlContent += '<tbody><tr><td><a href="good/goodDetails?gid='+ordersBean.gid+'"><img style="width: 50px;margin-top: 10px;" src="/zzbinGood/'+ordersBean.gpricpath+'"></a>&nbsp;&nbsp;</td><td width="170px">'+ordersBean.gname+'</td><td>$'+(ordersBean.price*ordersBean.discount).toFixed(2)+'</td><td>'+ordersBean.tname+'</td><td>'+ordersBean.tdesc+'</td><td>'+ordersBean.gcname+'</td><td>'+ordersBean.gsname+'</td><td>'+ordersBean.cnum+'</td><td>$'+ordersBean.cprice+'</td><td><button class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon">&#xe623;</i>待收货</button></td></tr></tbody>';
	      					}else if(item.state==5){
	      						htmlContent += '<tbody><tr><td><a href="good/goodDetails?gid='+ordersBean.gid+'"><img style="width: 50px;margin-top: 10px;" src="/zzbinGood/'+ordersBean.gpricpath+'"></a>&nbsp;&nbsp;</td><td width="170px">'+ordersBean.gname+'</td><td>$'+(ordersBean.price*ordersBean.discount).toFixed(2)+'</td><td>'+ordersBean.tname+'</td><td>'+ordersBean.tdesc+'</td><td>'+ordersBean.gcname+'</td><td>'+ordersBean.gsname+'</td><td>'+ordersBean.cnum+'</td><td>$'+ordersBean.cprice+'</td><td><button class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon">&#xe702;</i>已失效</button></td></tr></tbody>';
	      					}else{
		      					if(ordersBean.geid==0){
			      					htmlContent += '<tbody><tr><td><a href="good/goodDetails?gid='+ordersBean.gid+'"><img style="width: 50px;margin-top: 10px;" src="/zzbinGood/'+ordersBean.gpricpath+'"></a>&nbsp;&nbsp;</td><td width="170px">'+ordersBean.gname+'</td><td>$'+(ordersBean.price*ordersBean.discount).toFixed(2)+'</td><td>'+ordersBean.tname+'</td><td>'+ordersBean.tdesc+'</td><td>'+ordersBean.gcname+'</td><td>'+ordersBean.gsname+'</td><td>'+ordersBean.cnum+'</td><td>$'+ordersBean.cprice+'</td><td><button class="layui-btn layui-btn-warm layui-btn-xs" id="goodComm" value="'+ordersBean.obid+','+ordersBean.gid+','+item.oname+','+ordersBean.gcid+','+ordersBean.gsid+'"><i class="layui-icon">&#xe6b2;</i>待评价</button></td></tr></tbody>';
		      					}else{
		      						htmlContent += '<tbody><tr><td><a href="good/goodDetails?gid='+ordersBean.gid+'"><img style="width: 50px;margin-top: 10px;" src="/zzbinGood/'+ordersBean.gpricpath+'"></a>&nbsp;&nbsp;</td><td width="170px">'+ordersBean.gname+'</td><td>$'+(ordersBean.price*ordersBean.discount).toFixed(2)+'</td><td>'+ordersBean.tname+'</td><td>'+ordersBean.tdesc+'</td><td>'+ordersBean.gcname+'</td><td>'+ordersBean.gsname+'</td><td>'+ordersBean.cnum+'</td><td>$'+ordersBean.cprice+'</td><td><button class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon">&#xe702;</i>已评价</button></td></tr></tbody>';
		      					}
	      					} 
	      				});
	      				htmlContent += '</table></div>';
	      				htmlContent += '</div>';
	      			});
	      			$(".layui-collapse").append(htmlContent);	//追加页面元素
	      			element.init();
				}else{
					layer.msg("订单加载失败！",{"icon":5,"time":2000});
				}
				var counts = res.count;
				if(counts%limit==0){
					laef = counts/limit;
				}else{
					laef = parseInt(counts/limit)+1;
				}
			},
			error:function(){
				layer.msg("服务器异常！",{"icon":3,"time":2000});
			}
		});
	}
	
	//去支付
	$("#flowDiv .layui-collapse").on("click","#ordersPay",function(event){
		  var oname = $(this).parent().siblings().eq(0).text();
		  var oprice = $(this).parent().siblings().eq(1).text();
		  layer.confirm('确定支付？',{icon: 3,title: '提示'},function(index){
			  setTimeout('window.location="orders/ordersPay?oname='+oname+'&oprice='+oprice+'"',500);
			  layer.close(index);
		  });
		  return false;
	});
	
	//确认收货
	$("#flowDiv .layui-collapse").on("click","#ordersFinish",function(event){
		  var btn = $(this);
		  var spans = $(this).parent().siblings().eq(6);
		  var jsonOrders = {};
		  var gid = $(this).val().split(" ")[0].split(",");
		  var gcid = $(this).val().split(" ")[1].split(",");
		  var gsid = $(this).val().split(" ")[2].split(",");
		  var cnum = $(this).val().split(" ")[3].split(",");
		  jsonOrders['oname'] = $(this).parent().siblings().eq(0).text();
		  jsonOrders['state'] = 3;
		  jsonOrders['getOrderDate'] = new Date();
		  layer.confirm('确认收货？',{icon: 3,title: '提示'},function(index){
			  $.ajax({
					type:"post",
					url:'orders/updT',
					data:jsonOrders ,
					success:function(res){
						if(res=="success"){
							layer.msg("订单已收货，欢迎再次购买。",{"icon":1,"time":1000});
							//spans.replaceWith('<li class="layui-nav-item" style="margin-left: 10%;width: 80px;"><span style="color:blue;">已收货</span></li>');
							//btn.replaceWith('<button class="layui-btn layui-btn-xs" id="ordersAssess"><i class="layui-icon">&#xe6b2;</i>去评价</button>');
							setTimeout('window.location = "model/showOrders"', 500);
							for (var i = 0; i < gid.length; i++) {
								var jsonGoodNum = {};
								jsonGoodNum['gid'] = gid[i];
								jsonGoodNum['gcid'] = gcid[i];
								jsonGoodNum['gsid'] = gsid[i];
								loadGoodNum(jsonGoodNum,cnum);
							}
						}else{
							layer.msg("订单收货失败!",{"icon":2,"time":2000});
						}
					},
					error:function(){
						layer.msg("服务器异常。",{"icon":3,"time":2000});
					}
			  });
			  layer.close(index);
		  });
		  return false;
	});
	
	//加载商品数量(库存)
	function loadGoodNum(jsonGoodNum,cnum){
		$.ajax({
			type:"post",
			url:"goodnum/loadObjectByPramas",
			async:false,
			data:jsonGoodNum,
			success:function(data){
				if(data.gsales==null){
					data.gsales = 0;
				}
				jsonGoodNum['gsales'] = parseInt(data.gsales) + parseInt(cnum);
				updGoodNum(jsonGoodNum)
			},error:function(){
				swal("服务器异常!","","warning",{buttons: {}});
			}
		}); 
	}
	
	//修改商品数量(库存)
	function updGoodNum(jsonGoodNum){
		$.ajax({
			type:"post",
			url:"goodnum/updT",
			async:false,
			data:jsonGoodNum,
			success:function(data){
				
			},error:function(){
				swal("服务器异常!","","warning",{buttons: {}});
			}
		}); 
	}
	
	//订单评价
	$("#flowDiv .layui-collapse").on("click","#ordersComm",function(event){
		  var btn = $(this);
		  var spans = $(this).parent().siblings().eq(6);
		  var oname = $(this).parent().siblings().eq(0).text();
		  layer.confirm('确定评价？',{icon: 3,title: '提示'},function(index){
			  layer.open({
				  type:1,	//跳转类型
				  title:'订单评价',	//标题
				  area:['450px','550px'],
				  anim:4,
				  content: $("#ordersEvalauteDiv"),
			  	  shade: 0,	//不显示遮罩
			  	  success: function(index){		//bnt按钮的点击事件
			  		  	//订单价格
			  		  	rate.render({
			  		    elem: '#test1'
			  		    ,value: 3
			  		    ,text: true
			  		    ,setText: function(value){ //自定义文本的回调
			  		      $("#oePrice").val(value);
			  		      var arrs = {
		  			          '1': '很贵'
			  			      ,'2': '贵'
			  			      ,'3': '一般'
			  			      ,'4': '实惠'
			  			      ,'5': '很好'
			  			  };
			  			  this.span.text(arrs[value] || ( value + "星"));
			  		    }
			  		  })
			  		  //订单服务
			  		  rate.render({
			  		    elem: '#test2'
			  		    ,value: 3
			  		    ,text: true
			  		    ,setText: function(value){ //自定义文本的回调
			  		      $("#oeServer").val(value);
			  		      var arrs = {
		  			          '1': '非常差'
		  			          ,'2': '不满意'
		  			          ,'3': '一般'
		  			          ,'4': '满意'
		  			          ,'5': '很满意'
		  			      };
			  			  this.span.text(arrs[value] || ( value + "星"));
			  		    }
			  		  })
			  		  //整体打分
			  		  rate.render({
			  		    elem: '#test3'
			  		    ,value: 3
			  		    ,text: true
			  		    ,setText: function(value){ //自定义文本的回调
				  		  $("#oeOverall").val(value);
				  		  var arrs = {
		  			          '1': '非常差'
			  			      ,'2': '差'
			  			      ,'3': '一般'
			  			      ,'4': '好'
			  			      ,'5': '非常好'
		  			      };
			  			  this.span.text(arrs[value] || ( value + "星"));
			  		    }
			  		  })

			  		//监听提交
			  		form.on('submit(subOrdersEvalaute)', function(data){
			  			  /*layer.alert(JSON.stringify(data.field), {
			  		      	  title: '最终的提交信息'
			  		  	  })*/
			  			  var jsonOrdersEvalaute = {};
			  			  var ordersEvalaute = $("#ordersEvalauteForm").serializeArray();
			  			  $.each(ordersEvalaute,function(){
			  				jsonOrdersEvalaute[this.name] = this.value;
			  			  });
			  			  jsonOrdersEvalaute['oeDate'] = new Date();
			  			  //console.log(jsonOrdersEvalaute);
			  			  saveOrdersEvalaute(jsonOrdersEvalaute,oname,btn,spans);
			  			  layer.closeAll();
			  			  return false;
			  		});
			  		
			  	  }
	  		  });
			  layer.close(index);
		  });
		  return false;
	});

	//添加评论
	function saveOrdersEvalaute(jsonOrdersEvalaute,oname,btn,spans){
		  $.ajax({
				type:"post",
				url:'ordersEvalaute/saveOrdersEvalaute?oname='+oname,
				data:jsonOrdersEvalaute,
				success:function(res){
					if(res=="success"){
						layer.msg("评论发布成功。",{"icon":1,"time":2000});
						spans.replaceWith('<li class="layui-nav-item" style="margin-left: 10%;width: 80px;"><span style="color:gray;">已评价</span>');
						btn.replaceWith('<button class="layui-btn layui-btn-primary layui-btn-xs" id="ordersLook"><i class="layui-icon">&#xe705;</i>去查看</button>');
					}else{
						layer.msg("评论发布失败。",{"icon":2,"time":2000});
					}
				},
				error:function(){
					layer.msg("服务器异常。",{"icon":3,"time":2000});
				}
		  });
	}

	//查看评论
	$("#flowDiv .layui-collapse").on("click","#ordersLook",function(event){
		var oname = $(this).parent().siblings().eq(0).text();
		var jsonOrders = {};
		jsonOrders['oname'] = oname;
		$.ajax({
			type:"post",
			url:'orders/loadObjectByPramas',
			data:jsonOrders,
			success:function(res){
				  var htmlContent = '';
				  htmlContent += '<h2 align="center" style="margin-top: 10px;">查看评价</h2>';
				  htmlContent += '<p style="margin-left: 50px;margin-top: 20px;">价格评价：'+res.ordersEvalaute.oeStrPrice+'</p>';
				  htmlContent += '<p style="margin-left: 50px;margin-top: 20px;">服务评价：'+res.ordersEvalaute.oeStrServer+'</p>';
				  htmlContent += '<p style="margin-left: 50px;margin-top: 20px;">整体评价：'+res.ordersEvalaute.oeStrOverall+'</p>';
				  htmlContent += '<p style="margin-left: 50px;margin-top: 20px;">评价内容：'+res.ordersEvalaute.oeContent+'</p>';
				  layer.open({
					  type: 1,
					  title: '查看评价',
					  offset: 'cb',	//弹出框弹出的坐标位置（cb:中间）
					  content: htmlContent,
					  area: ['400px','400px'],
				  	  btn: '关闭',
				  	  btnAlign: 'cb',	//按钮右下角
				  	  shade: 0,	//不显示遮罩
				  	  yes: function(index){		//bnt按钮的点击事件
				  		  
				  		  layer.close(index);
				  	  }
				  });
			},
			error:function(){
				layer.msg("服务器异常。",{"icon":3,"time":2000});
			}
		});
	});
	
	//商品评价
	$("#flowDiv .layui-collapse").on("click","#goodComm",function(event){
		  var btn = $(this);
		  var obid = $(this).val().split(",")[0];
		  var gid = $(this).val().split(",")[1];
		  var oname = $(this).val().split(",")[2];
		  var gcid = $(this).val().split(",")[3]
		  var gsid = $(this).val().split(",")[4]
		  layer.confirm('确定评价？',{icon: 3,title: '提示'},function(index){
			  layer.open({
				  type:1,	//跳转类型
				  title:'商品评价',	//标题
				  area:['450px','550px'],
				  anim:4,
				  content: $("#goodEvalauteDiv"),
			  	  shade: 0,	//不显示遮罩
			  	  success: function(index){		//bnt按钮的点击事件
			  		  	//订单价格
			  		  	rate.render({
			  		    elem: '#test4'
			  		    ,value: 3
			  		    ,text: true
			  		    ,setText: function(value){ //自定义文本的回调
			  		      $("#gePrice").val(value);
			  		      var arrs = {
		  			          '1': '很贵'
			  			      ,'2': '贵'
			  			      ,'3': '一般'
			  			      ,'4': '实惠'
			  			      ,'5': '很好'
			  			  };
			  			  this.span.text(arrs[value] || ( value + "星"));
			  		    }
			  		  })
			  		  //订单服务
			  		  rate.render({
			  		    elem: '#test5'
			  		    ,value: 3
			  		    ,text: true
			  		    ,setText: function(value){ //自定义文本的回调
			  		      $("#geServer").val(value);
			  		      var arrs = {
		  			          '1': '非常差'
		  			          ,'2': '不满意'
		  			          ,'3': '一般'
		  			          ,'4': '满意'
		  			          ,'5': '很满意'
		  			      };
			  			  this.span.text(arrs[value] || ( value + "星"));
			  		    }
			  		  })
			  		  //整体打分
			  		  rate.render({
			  		    elem: '#test6'
			  		    ,value: 3
			  		    ,text: true
			  		    ,setText: function(value){ //自定义文本的回调
				  		  $("#geOverall").val(value);
				  		  var arrs = {
		  			          '1': '非常差'
			  			      ,'2': '差'
			  			      ,'3': '一般'
			  			      ,'4': '好'
			  			      ,'5': '非常好'
		  			      };
			  			  this.span.text(arrs[value] || ( value + "星"));
			  		    }
			  		  })

			  		//监听提交
			  		form.on('submit(subGoodEvalaute)', function(data){
			  			  /*layer.alert(JSON.stringify(data.field), {
			  		      	  title: '最终的提交信息'
			  		  	  })*/
			  			  var jsonGoodEvalaute = {};
			  			  var goodEvalaute = $("#goodEvalauteForm").serializeArray();
			  			  $.each(goodEvalaute,function(){
			  				jsonGoodEvalaute[this.name] = this.value;
			  			  });
			  			  jsonGoodEvalaute['geDate'] = new Date();
			  			  jsonGoodEvalaute['good.gid'] = gid;
			  			  jsonGoodEvalaute['user.uid'] = $("#uid").val();
			  			  jsonGoodEvalaute['goodColor.gcid'] = gcid;
			  			  jsonGoodEvalaute['goodSize.gsid'] = gsid;
			  			  //console.log(jsonGoodEvalaute);
			  			  saveGoodEvalaute(jsonGoodEvalaute,oname,obid,btn);
			  			  layer.closeAll();
			  			  return false;
			  		});
			  	  }
	  		  });
			  layer.close(index);
		  });
		  return false;
	});
	
	//添加商品评论
	function saveGoodEvalaute(jsonGoodEvalaute,oname,obid,btn){
		  $.ajax({
				type:"post",
				url:'goodEvaluate/saveGoodEvaluate?oname='+oname+'&obid='+obid,
				data:jsonGoodEvalaute,
				success:function(res){
					if(res=="success"){
						layer.msg("评论发布成功。",{"icon":1,"time":2000});
						btn.replaceWith('<button class="layui-btn layui-btn-disabled layui-btn-xs"><i class="layui-icon">&#xe702;</i>已评价</button>');
					}else{
						layer.msg("评论发布失败。",{"icon":2,"time":2000});
					}
				},
				error:function(){
					layer.msg("服务器异常。",{"icon":3,"time":2000});
				}
		  });
	}
	
	//将时间戳转换为yyyy,MM,dd,HH,mm,ss
	function formatDateTime(inputTime) {  
	    var date = new Date(inputTime);
	    var y = date.getFullYear();
	    var m = date.getMonth() + 1;
	    m = m < 10 ? ('0' + m) : m;
	    var d = date.getDate();
	    d = d < 10 ? ('0' + d) : d;
	    var h = date.getHours();
	    h = h < 10 ? ('0' + h) : h;
	    var minute = date.getMinutes();
	    var second = date.getSeconds();
	    minute = minute < 10 ? ('0' + minute) : minute;  
	    second = second < 10 ? ('0' + second) : second; 
	    return y + ',' + m + ',' + d+','+h+','+minute+','+second;
	};
	
	//将时间戳转换为yyyy-MM-dd HH:mm:ss
	function getDateTime(inputTime) {  
	    var date = new Date(inputTime);
	    var y = date.getFullYear();
	    var m = date.getMonth() + 1;
	    m = m < 10 ? ('0' + m) : m;
	    var d = date.getDate();
	    d = d < 10 ? ('0' + d) : d;
	    var h = date.getHours();
	    h = h < 10 ? ('0' + h) : h;
	    var minute = date.getMinutes();
	    var second = date.getSeconds();
	    minute = minute < 10 ? ('0' + minute) : minute;  
	    second = second < 10 ? ('0' + second) : second; 
	    return y + '/' + m + '/' + d+' '+h+':'+minute+':'+second;
	};
	
});